# coding: utf-8
# Author: legend
# @Time： 2020/8/27 下午10:05
import logging

from utils.messages.handler import BaseHandler
from websocket.messages import LatestDeviceNetworkCardStatusResponse, MultiDeviceNetworkCardStatusResponse

logger = logging.getLogger('app.running.log')


class LatestDeviceNetworkCardStatusRequestHandler(BaseHandler):

    async def do(self, *args, **kwargs):
        device_id = kwargs.get('device_id')
        result_value = self.get_monitor_data(0, device_id, 'if.status', 1, True)
        return {
            'data': result_value,
            'result_code': LatestDeviceNetworkCardStatusResponse.ResultCode.NORMAL
        }


class MultiDeviceNetworkCardStatusRequestHandler(BaseHandler):

    async def do(self, *args, **kwargs):
        device_id = kwargs.get('device_id')
        size = kwargs.get('size')
        result_value = self.get_monitor_data(0, device_id, 'if.status', size, True)
        return {
            'result_code': MultiDeviceNetworkCardStatusResponse.ResultCode.NORMAL,
            'data': list(reversed(result_value))
        }
